[MUSIC]
Hello and welcome to the step by step demo of how to use the try catch
activity to resolve an issue in a workflow that displays an error
while reading data from an Excel file. We'll demonstrate this by
creating a workflow that will read data from an Excel file. The Excel file will be left open while
running the workflow because every time we leave the file open it
will throw an exception. We'll catch the exception and
rectify it using the try catch activity. We'll use a try catch activity
to close the Excel file and then attempt to read the file. Search for a sequence activity in
the activities panel and drag and drop it in the designer panel. Rename the activity as reading Excel
data and add an annotation to it. Search for a reed range activity in
the activities panel and drag and drop it in the sequence activity,
rename it as read range, read Excel data. Click on the folder icon to
open the file Explorer and select the Excel file from
which the data is to be read. Here the name of the Excel file that
we're using is employee data.XLSX. Empty the range text box so
that the entire Excel sheet can be read. Navigate to the properties panel and
in the data table property press Ctrl+K on your keyboard
to create a new variable and enter DT underscore employee
data as the variable name. This is the variable where the data
from the Excel file will be stored. Now let's open the Excel file. Now in my path studio click Save to save the project and run it. You can see that runtime
execution error is displayed. It says that the process cannot access the
file because another process is using it. It means that the Excel file
should not be open while running the workflow,
click OK to close this pop up. Search for a try catch activity
in the activities panel and drag and drop it's below the read range
activity, rename it as close Excel file. Drag on drop the read range activity in
the Tri section of the try catch activity. Click on the add new catch
in the catches section and select system .io.io
exception from the drop down menu which stands for
invalid operation exception. Search for a write line activity
in the activities panel and drag and drop it into catches
section of the try catch activity. Rename it to display error,
navigate to its properties panel and click on the ellipsis icon of the text
property to open the expression editor. Enter the expression exception.message.tostring+"at'+exception- .source.tostring. This expression will print the errors
encountered by the process in the output panel. Search for a click activity
in the activities panel and drag and
drop it below the write line activity. Rename it as close Excel file, click
the indicate elements on screen link and indicate the close button at the top
right corner of the Excel file Window. This activity will close
the Excel file if it's open, click on the hamburger button and select
edit selector from the drop down menu. In the selector editor Window,
uncheck the title box and click the validate button to ensure
that the selector is valid and click OK. Now let's use to write line
activities to indicate this start and end of the reading of the Excel file. Search for a write line activity in the activities panel and drag and drop it above the try catch activity, rename it to start. In its text box enter
the text reading Excel file. Drag and
drop another write line activity below the try catch activity, rename it to end. In its text box, enter the text
Excel file read successfully, expand the finally section
of the try catch activity. Search for an if activity in
the activities panel and drag and drop it in the finally section. Rename it to check empty variable,
in its condition text box enter the expression DT underscore
employee data is nothing. Search for a reed range activity in
the activities panel and drag and drop it in the then section of the if activity,
rename it to read Excel data again. This if activity will check
whether the data table variable DT underscore employee data is empty. If it is found empty then an attempt
to read the Excel file will be made, click on the folder icon of this
activity to open the file Explorer and select the employee data.XLSX file
from which the data is to be read. Empty the range text box so
that the entire Excel sheet can be read. Navigate to the properties panel and
in the data table property, enter DT underscore employee data. Let's run this workflow now,
click Save to save the project and click run from the debug file
option to run the workflow. Let's open the output panel. You can see that the workflow
executes successfully. It means that the invalid operation
exception has been handled successfully by the try catch activity. Thanks for watching, goodbye.